package com.jiyinit.web.core.common.interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p></p>
 * <p>
 * <PRE>
 * <BR>	修改记录
 * <BR>-----------------------------------------------
 * <BR>	修改日期			修改人			修改内容
 * </PRE>
 *
 * @author lishaochuan
 * @version 1.0
 * @date 2017/4/11 14:12
 * @since 1.0
 */
public class InitGlobalParamsInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String serverHost = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
        String serverContext = request.getContextPath().equalsIgnoreCase("/") ? "" : request.getContextPath();
        String basePath = null;
        if (serverHost != null && serverContext != null) {
            basePath = serverHost + serverContext;
        }
        request.setAttribute("basePath", basePath);

        return super.preHandle(request, response, handler);
    }
}
